package com.jackiepenghe.datepickerrange

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.jackiepenghe.rangedatepickerlibrary.Logger
import com.jackiepenghe.rangedatepickerlibrary.RangeDatePickerView
import com.jackiepenghe.rangedatepickerlibrary.listener.OnDateSelectChangedListener
import java.util.Date

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Logger.setLogLevel(Logger.LEVEL_ERROR)
        setContentView(R.layout.activity_main)
        val rangeDatePickerView = findViewById<RangeDatePickerView>(R.id.range_date_picker)
        rangeDatePickerView.setDateItemBackgroundSingleSelectRes(R.drawable.test_bg)
        rangeDatePickerView.setOnDateSelectChangedListener(object : OnDateSelectChangedListener {
            /**
             * 日期选择回调
             * @param startDate 选择的起始日期
             * @param endDate 选择的结束日期
             */
            override fun onDataSelect(startDate: Date?, endDate: Date?, differDay: Int) {
                Log.e("TAG", "onDataSelect: " )
                Log.w(
                    "TAG",
                    "onDataSelect: startDate = ${startDate.toString()} endDate = ${endDate.toString()} differDay = $differDay"
                )
            }

            /**
             * 选择的日期超过最大数量
             * @param date 选择的日期
             * @param dateMaxSelectCount 最大天数
             * @param differDay 选择的日期包含的天数
             */
            override fun onDataRangeOutOfMax(date: Date, dateMaxSelectCount: Int, differDay: Int) {
                Log.w("TAG","onDataRangeOutOfMax")
                Log.e(
                    "TAG",
                    "onDataSelect: date = $date dateMaxSelectCount = $dateMaxSelectCount differDay = $differDay"
                )
            }

        })
    }
}